package com.suixinsanren.design.compound.study.demo05;

import java.util.ArrayList;

public class Flock implements Quackable {

    private final ArrayList<Quackable> quackers = new ArrayList<>();
    private final Observable observable;

    public Flock() {
        this.observable = new Observable(this);
    }

    public void add(Quackable quacker) {
        quackers.add(quacker);
    }


    @Override
    public void quack() {
        quackers.forEach(Quackable::quack);
    }

    @Override
    public void registerObserver(Observer observer) {
        quackers.forEach(duck -> duck.registerObserver(observer));
    }

    @Override
    public void notifyObservers() {
    }

    @Override
    public String toString() {
        return "Flock of Ducks";
    }
}
